package Carte;

import java.util.GregorianCalendar;

public class Calendrier {

	public static String toString(GregorianCalendar gre) {
		String date;
		
		String month= "";
		String day=String.valueOf(gre.get(GregorianCalendar.DAY_OF_MONTH));
		String year=String.valueOf(gre.get(GregorianCalendar.YEAR));
		String hours=String.valueOf(gre.get(GregorianCalendar.HOUR_OF_DAY));
		String minutes=String.valueOf(gre.get(GregorianCalendar.MINUTE));

		switch(gre.get(GregorianCalendar.MONTH)){
		case 0 :
			month = "Janvier"; 
			break;
		case 1 :
			month = "Fevrier"; 
			break;
		case 2 :
			month = "Mars"; 
			break;
		case 3 :
			month = "Avril"; 
			break;
		case 4 :
			month = "Mai"; 
			break;
		case 5 :
			month = "Juin"; 
			break;
		case 6 :
			month = "Juillet"; 
			break;
		case 7 :
			month = "Aout"; 
			break;
		case 8 :
			month = "Septembre"; 
			break;
		case 9 :
			month = "Octobre"; 
			break;
		case 10 :
			month = "Novembre"; 
			break;
		case 11:
			month = "Decembre"; 
			break;

		}

		date = day + " " + month + " " + year + " - " + hours +"h:" + minutes + "m";
		return date;
	}

	public static void print(GregorianCalendar gre){
		System.out.println(toString(gre));
	}

	public static void main(String[] args) {
		GregorianCalendar gre = new GregorianCalendar();
		Calendrier.print(gre);
	}
	
	/**
	 * Savoir si la date de depart est avant la date d'arrive
	 * @param dateDepart
	 * @param dateArrive
	 */
	public static boolean dateBefore(GregorianCalendar dateDepart, GregorianCalendar dateArrive){
		if((dateArrive.getTimeInMillis() < dateDepart.getTimeInMillis())){
			return false;
		}
		
		return true;
	}
	
	/**
	 * Savoir si une date est valide
	 * La date doit etre superieur a la date du jour
	 * @param greDate
	 */
	public static boolean dateValide(GregorianCalendar greDate){
		GregorianCalendar greDateDuJour = new GregorianCalendar();
		if((greDate.getTimeInMillis() < greDateDuJour.getTimeInMillis())){
			return false;
		}
		
		/**
		 * Verifier l'année
		 */
		if(greDate.get(GregorianCalendar.YEAR) > 2020){
			return false;
		}
		
		
		
		/**
		 * Verifier le mois
		 */
		if(greDate.get(GregorianCalendar.MONTH) > 12){
			return false;
		}
		
		/**
		 * Verifier le jour
		 */
		if(greDate.get(GregorianCalendar.DAY_OF_MONTH) > 31){
			return false;
		}
		
		/**
		 * Verifier l'heure
		 */
		if(greDate.get(GregorianCalendar.HOUR_OF_DAY) > 24){
			return false;
		}

		/**
		 * Verifier les minutes
		 */
		if(greDate.get(GregorianCalendar.MINUTE) > 60){
			return false;
		}
		return true;
	}
	
	/**
	 * Savoir si une date est valide
	 * La date doit etre superieur a la date du jour
	 * @param greDate
	 */
	public static boolean dateValide(int years, int month, int day, int hour, int minute){
		GregorianCalendar greDateDuJour = new GregorianCalendar();
		
		if(years < greDateDuJour.get(GregorianCalendar.YEAR)){
			return false;
		}
		
		/**
		 * Verifier l'année
		 */
		if(years > 2020){
			return false;
		}
		
		
		
		/**
		 * Verifier le mois
		 */
		if(month > 12){
			return false;
		}
		
		/**
		 * Verifier le jour
		 */
		if(day > 31){
			return false;
		}
		
		/**
		 * Verifier l'heure
		 */
		if(hour > 24){
			return false;
		}

		/**
		 * Verifier les minutes
		 */
		if(minute > 60){
			return false;
		}
		
		return true;
	}
	
	/**
	 * Convertir les valeurs en gregorian calendar
	 * @param years
	 * @param month -1
	 * @param day
	 * @param hour
	 * @param second
	 * @return
	 */
	public static GregorianCalendar ValuesToGregorian(int years, int month, int day, int hour, int minute){
		return new GregorianCalendar(years, month-1, day, hour, minute);
	}
}
